import {openModal} from '@/utils/index.js';
import UserTaskConfiguration from '@/components/flow/nodeConfiguration/UserTaskConfiguration.vue';
import FlowModelInstance from '@/components/flow/typs/FlowModelInstance.js';

export default class EditUserTaskCommand {
  constructor(supportInstance, nodeId) {
    this.supportInstance = supportInstance;
    this.nodeId = nodeId;
  }

  serve() {
    let flowModelInstance = new FlowModelInstance(this.supportInstance.getModel());
    openModal(UserTaskConfiguration, {
      userTask: flowModelInstance.getNodeById(this.nodeId),
      service: this.supportInstance.service,
      formType: this.supportInstance.getModel().formType,
      userConfig: this.supportInstance.userConfig,
      taskViewAndAuthConfig: this.supportInstance.taskViewAndAuthConfig,
      flowModelInstance
    }, userTask => {
      flowModelInstance.replaceNode(userTask);
      this.supportInstance.setModel(flowModelInstance.getModelString());
    });
  }
}